package com.ogawa.chair7808.widget

import android.content.Context
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
import com.jeremyliao.liveeventbus.LiveEventBus
import com.ogawa.base.Constant.CommmandNum
import com.ogawa.base.Constant.MqttConstant
import com.ogawa.base.bean.ReceiveMassageBean
import com.ogawa.base.utils.CommonUtil
import com.ogawa.chair7808.cache.isPause
import com.ogawa.chair7808.manager.DataManager
import com.ogawa.chair7808.manager.DataManager.Companion.dataManager
import com.ogawa.chair7808.ui.activity.BaseActivity

class ViewIvPause @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : AppCompatImageView(context, attrs, defStyleAttr) {
    private val baseActivity = context as BaseActivity
    override fun onFinishInflate() {
        super.onFinishInflate()
        isSelected = isPause
        LiveEventBus.get(MqttConstant.LIVE_EVENT_BUS_KEY_RECEIVE_MESSAGE, ReceiveMassageBean::class.java).observe(baseActivity, {
            isSelected = isPause
        })
        this.setOnClickListener {
            if (CommonUtil.isFastClick()) {
                return@setOnClickListener
            } else {
                dataManager.sendCommond(CommmandNum.PAUSE, "5")
            } }
    }

}